package com.example.demo.dao;

import com.example.demo.pojo.WorkUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class SqlUser {
    @Autowired
    JdbcTemplate jdbcTemplate;
    public  List<WorkUser> getUserByIdAndOrEmail(String IdOrEmail, String pwd){
        String sql="select * from workuser a " +
                "where ( a.id='"+ IdOrEmail+ "'or a.email='"+IdOrEmail+"') " +
                "and (a.password='"+pwd+"')";
        return  jdbcTemplate.query(sql,(rs, rowNum) -> {
            return new WorkUser(
                    rs.getString("id"),
                    rs.getString("name"),
                    rs.getString("email"),
                    rs.getString("img_url"),
                    rs.getString("type"),
                    rs.getString("password"),
                    rs.getString("email_num"),
                    rs.getString("tel"),
                    rs.getString("sex"),
                    rs.getString("pet_name")
            );
        });
    }
}
